import Vue from 'vue'
import store from '@/store'
import router from '@/router'
import ElementUI from 'element-ui'
Vue.use(ElementUI)
// 全局提示信息
Vue.prototype.msgSuccess = function(msg) {
  Vue.prototype.$message({ showClose: true, message: msg, type: 'success', duration: 2000 })
}

Vue.prototype.msgError = function(msg) {
  Vue.prototype.$message({ showClose: true, message: msg, type: 'error', duration: 2000 })
}

Vue.prototype.msgWarning = function(msg) {
  Vue.prototype.$message({ showClose: true, message: msg, type: 'warning', duration: 2000 })
}

Vue.prototype.msgInfo = function(msg) {
  Vue.prototype.$alert(msg, '提示', {
    confirmButtonText: '确定',
    type: 'info',
    callback: action => {
    }
  })
}
Vue.prototype.msgInfoAdd = function(res, url, query) {
  if (res.code === 200) {
    this.msgSuccess(res.message)
    store.state.tagsView.visitedViews.splice(store.state.tagsView.visitedViews.findIndex(item => item.path === router.history.current.path.path), 1)
    router.push({
      path: url,
      query: query
    })
  } else if (res.code === 202) {
    Vue.prototype.$alert(res.message, '提示', {
      confirmButtonText: '确定',
      type: 'info',
      callback: action => {
        store.state.tagsView.visitedViews.splice(store.state.tagsView.visitedViews.findIndex(item => item.path === router.history.current.path.path), 1)
        router.push({
          path: url
        })
      }
    })
  } else {
    Vue.prototype.msgError(res.message)
    return
  }
}
